const SpeakService = require("../sercice/SpeakService")


const SpeakControl = {
    speak_add: async (req, res) => {
        try {
            const result = await SpeakService.add_speak(req.body)
            res.status(200).send({
                msg: "添加成功",
                code: 200
            })
        } catch (error) {
            console.log(error.message)
            res.status(411).send({
                msg: "添加失败",
                code: 411
            })
        }

    },
    get_list: async (req, res) => {
        try {
            const result = await SpeakService.get_lsit(req.params.id)
            res.status(200).send({
                msg: "获取成功",

                data: result.data,
                count: result.count,

                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: {},
                code: 411
            })
        }
    },
    put_one: async (req, res) => {
        try {
            const result = await SpeakService.one_put(req.body)
            if (result.matchedCount === 1) {
                res.status(200).send({
                    msg: "修改成功",
                    code: 200
                })
            } else {
                res.status(411).send({
                    msg: "修改失败",
                    code: 411
                })
            }
        } catch (error) {
            res.status(411).send({
                msg: "修改失败",
                code: 411
            })
        }
    },
    delete_one: async (req, res) => {
        try {
            const result = await SpeakService.one_delete(req.params.id)
            console.log(result, '刹车农户')
            if (result.deletedCount == 1) {
                res.send({
                    msg: '删除成功',
                    code: 200
                })
            } else {
                res.send({
                    mssg: "删除失败",
                    code: 411
                })
            }

        } catch (error) {
            res.send({
                mssg: "删除失败",
                code: 411
            })
        }
    }
}
module.exports = SpeakControl
